****************************************************************************************************************************
********The wrong place at the wrong time? Territorial autonomy and conflict during regime transitions********
*****CEE-FSU Instrumental variables approach*****
*****Andreas Juon & Daniel Bochsler 2023 (Comparative Political Studies)*****
****************************************************************************************************************************

************************************************************************************
*********1. Libraries, data import, definitions*********
************************************************************************************

******1.1 Data******
cd "[!!!Set working directory containing the data file!!!]"
insheet using "./juon_bochsler_cps_autonomy.csv", clear
drop if status_no >= 3
drop if !(cowcode == 290 | cowcode == 310 | cowcode == 315 | cowcode == 316 | cowcode == 317 | cowcode == 339 | cowcode == 341 | cowcode == 343 | cowcode == 344 | cowcode == 345 | cowcode == 346 | cowcode == 347 | cowcode == 349 | cowcode == 355 | cowcode == 359 | cowcode == 360 | cowcode == 365 | cowcode == 366 | cowcode == 367 | cowcode == 368 | cowcode == 369 | cowcode == 370 | cowcode == 371 | cowcode == 372 | cowcode == 373 | cowcode == 701 | cowcode == 702 | cowcode == 703 | cowcode == 704 | cowcode == 705)
drop if year <= 1989

******1.2 Constructing variables******
gen ldistance_border = log(distance_border + 1)
gen lgdppc_l1 = log(gdppc_l1)
gen lpop = log(pop)
drop ldistance_border
gen ldistance_border = log(distance_border + 1)
gen years_no_sd_l12 = years_no_sd_l1^2
gen years_no_sd_l13 = years_no_sd_l1^3
gen years_no_violsd_l12 = years_no_violsd_l1^2
gen years_no_violsd_l13 = years_no_violsd_l1^3

******1.3 Defining variable lists (macros)******
global group_controls state_control included size ldistance_border tek_sup_irre_any tek_sdm oil_area_pct
global country_controls lgdppc_l1 lpop sd_sum_l1 polityca
global sd_years years_no_sd_l1 years_no_sd_l12 years_no_sd_l13
global violsd_years sd_l1 years_no_violsd_l1 years_no_violsd_l12 years_no_violsd_l13


************************************************************************************
*********2. IV Models*********
************************************************************************************

******2.1. SDM onset******
*IV probit
ivprobit sd_onset (terraut = terraut_1989) $group_controls $country_controls $sd_years if sd_l1 == 0 & cee_fsu_transition == 1, vce(cl cowcode) first
*margins
margins, dydx(terraut) predict(pr)
*diagnostics
ivreg2 sd_onset (terraut = terraut_1989) $group_controls $country_controls $sd_years if sd_l1 == 0 & cee_fsu_transition == 1, ffirst  robust cluster(cowcode)
mat list e(first)

******2.2 Concession******
*IV probit
ivprobit terraut_up (terraut = terraut_1989) $group_controls $country_controls if sd_l1 == 1 & sd_period_terraut_up_l1==0 & cee_fsu_transition == 1, vce(cl cowcode) first
*margins
margins, dydx(terraut) predict(pr)
*diagnostics
ivreg2 terraut_up (terraut = terraut_1989) $group_controls $country_controls if sd_l1 == 1 & sd_period_terraut_up_l1==0 & cee_fsu_transition == 1, ffirst  robust cluster(cowcode)
mat list e(first)


******2.3. Escalation during SDM******
*IV probit
ivprobit violsd_onset (terraut = terraut_1989) $group_controls $country_controls $violsd_years if sd_l1 == 1 & violsd_l1 == 0 & cee_fsu_transition == 1, vce(cl cowcode) first
*margins
margins, dydx(terraut) predict(pr)
*diagnostics
ivreg2 violsd_onset (terraut = terraut_1989) recent_concession5 $group_controls $country_controls $violsd_years if sd_l1 == 1 & violsd_l1 == 0 & cee_fsu_transition == 1, ffirst  robust cluster(cowcode)
mat list e(first)


